package com.qdlc.p2p.biz.task.flow;

import org.apache.log4j.Logger;


/**
 * 流转标线程
 * @author wjx
 * @version 2.0
 * @date 2015年5月28日 下午3:57:00
 */
public class FlowAbstractLoanTask implements FlowLoanTask {
	private Logger logger = Logger.getLogger(FlowAbstractLoanTask.class);
	public Thread task = new Thread("Task") {

		private boolean isRun = true;

		@Override
		public void run() {
			while (isRun) {
				logger.debug(this.getName() + " Running!");
                try {
                    doLoan();
                } catch (Exception ex){
                    ex.printStackTrace();
                    logger.trace(ex);
                }
				doWait();
			}
		}

		@SuppressWarnings("unused")
		public void stopThread() {
			isRun = false;
		}

	};

	public FlowAbstractLoanTask() {
		task.start();
		logger.debug("线程启动！");
	}

	@Override
	public void execute() {
		logger.debug("task.execute()");
		Object lock = getLock();
		synchronized (lock) {
			lock.notifyAll();
		}
	}

	@Override
	public void doLoan() {
		logger.debug("AbstractTask开始");
	}

	public void doWait() {
		Object lock = this.getLock();
		synchronized (getLock()) {
			try {
				lock.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	@Override
	public void stop() {

	}

	@Override
	public Object getLock() {
		return FlowLoanTask.LOAN_STATUS;
	}

}
